<form action="index.php/payment_plan/update/" method="post" name="myform" id="myform">
<div id="inline5">
<h2><span>详细信息</span></h2>
<table>
        <tr><th colspan="5">回款计划：</th></tr>
        <tr>
            <td class="name" width="100"><span>*</span>客户：</td>
            <td colspan="4"><input id="customer_name" autocomplete="off" style="" type="text" name="customer_name" value=<?= $edit_plans->customer_name?>></input></td>
        </tr>
        <tr>
        	<td class="name" width="100">合同/订单：</td>
            <td colspan="4">
				<select id="plan_contacter_name" name="contract_id" style=" width:275px;">
						<option value="<?= $edit_plans->contract_id?>"><?= $edit_plans->contract_subject?></option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">计划回款日期：</td>
            <td><input name="payment_time" type="text" class="datepicker" id="find_time"  style="background:url(images/calendar.gif) right 1px no-repeat;" value=<?= $edit_plans->payment_time?> ></input></td>
        </tr>
        <tr class="je_g">
            <td class="name" width="100">期次：</td>
            <td>
            	<select name="stages" id="stages">
            	    <?php for($i=1;$i<=12;$i++){?>
                	<option value="<?= $i?>" <?php if($edit_plans->stages == $i):?>selected="selected"<?php endif;?>><?php echo $i;?></option>
                    <?php }?>
                </select>
            </td>
        </tr>
        <script type="text/javascript">
		$(document).ready(function(){
			$("#stages").change(function(){
				var je='';
				for(var i=0;i<$("#stages").val();i++){
					je+='<tr class="je_g_c"><td class="name" width="100">金额：</td> <td><input class="input_bg1" name="money'+i+'" id="money'+i+'" type="text" id="principal" value= ></input><input type="text" name="stages_payment_time'+i+'" class="input_bg2 datepicker" /></td></tr>';	
				}
				$(".je_g_c").html("");	
				$(".je_g").after(je);
				$( ".datepicker" ).datepicker();
			})	
			
		});	
		</script>
		<?php $i=0;?>
		<?php foreach($stages as $stage):?>
		<tr class="je_g_c">
            <td class="name" width="100">金额：</td>
            <?php 
            $datatime = strtotime($stage->stages_payment_time);
            $stages_payment_time = date( "Y-m-d",$datatime);
            ?>
            <td><input class="input_bg1" name="money<?= $i?>" id="money<?= $i?>" type="text" id="principal" value=<?= $stage->money?> ></input><input type="text" class="input_bg2 datepicker" name="stages_payment_time<?= $i?>" value="<?= $stages_payment_time?>"/></td>
        </tr>
        <?php $i++;?>
		<?php endforeach;?>
        <tr>
            <td class="name" width="100">所有者：</td>
            <td>
            	<select name="owner_id" style=" width:275px;">
            		<?php foreach($users as $user):?>
            			<?php if($user->user_name != '何俊斌'):?>
            				<option <?php if($edit_plans->owner_id == $user->id):?>selected="selected"<?php endif;?> value="<?= $user->id?>"><?= $user->user_name?></option>
            			<?php endif;?>
                	<?php endforeach;?>
                </select>
            </td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset""重置" /></td>
        </tr>
    </table>
</div>
<input type="hidden" name="create_time" value="<?= $edit_plans->create_time?>" ></input>
<input type="hidden" name="id" value="<?= $edit_plans->id?>" ></input>
<input type="hidden" id="total_money" value="<?= $edit_plans->money?>" ></input>
</form>

<input type="hidden" id="type" value="2" ></input>
<script type="text/javascript">
$("#tijiao").click(function(){
	var customer_name = $("#customer_name").val();
	var val = $("#stages").val();
	var total=0;
	if(!customer_name){
		alert('客户名不允许为空');
	}else{
		for(var i=0;i<val;i++){
			var money=$("#money"+i+"").val();
			total+=parseFloat(money);
		}
		var total_money=$("#total_money").val();
		if(total > total_money){
			alert('输入的金额大于合同总金额');
		}
		if(total < total_money){
			alert('输入的金额小于合同总金额');
		}
		if(total == total_money){
			$("#myform").submit();
		}
	}
})
</script>
<script type="text/javascript">
$(function() {
		$( ".datepicker" ).datepicker();

});
</script>